<template>
	<view class="container">
		<view class="uni-one">
			{{month +  objPage[`${type}`].name}}
		</view>
		<view class="uni-two">
			{{allAccount}}
		</view>
		<view class="class-main">
			<view class="uni-main" v-for="(item,index) of objectData" :key="index">
				<template
					v-if="item.price !==0  &&  item.price !== '0' &&   item.price !== '-0' &&    item.price !== '-'">
					<text class="uni-left">{{item.name}}</text>
					<text class="uni-right" :class="{'colorRed':item.price > 0}">
						{{ item.price > 0 ? handlerC(item) : item.price }}</text>
				</template>
			</view>
		</view>
		<waterMark />
	</view>
</template>

<script>
	import {
		result,
		resultType
	} from "./config.js"
	import {
		getReportDataMonth
	} from '../../api';
	import {
		ThousandAndDecimal
	} from '../../utils/base.js';
	import waterMark from '../../components/waterMark.vue'
	import {
		Object
	} from "core-js/web/timers";
	export default {
		components: {
			waterMark
		},
		data() {
			return {
				objectData: [],
				allAccount: "",
				config: null,
				param: {
					storeCode: '',
					month: ''
				},
				month: "",
				type: null,
				objPage: {
					'1': {
						name: "月收款一(元)",
						price: ""
					},
					'2': {
						name: "月收款二(元)",
						price: ""
					},

				}
			};
		},
		onLoad(options) {
			this.type = +options.type;
			this.params = {
				storeCode: options.storeCode,
				month: options.month
			}
			this.month = +(this.params.month.slice(4, 6))
			console.log(this.month, "----")
			// if (this.type == 1) {	}
			this.getDataMonth(this.params)


		},

		methods: {
			ThousandAndDecimal,
			handlerC(row) {
				return (row.name == "月营业额" || row.name == "毛利") ? row.price : '+' + row.price;
			},
			// hanlerDataValue(val) {
			// 	val = val ? this.ThousandAndDecimal(+val) : '-'
			// 	return val
			// },
			// 月度报表数据 getReportDataMonth
			async getDataMonth(params) {
				try {
					const {
						data,
						code
					} = await getReportDataMonth(params)
					if (code == "000") {
						this.allAccount = this.type == 1 ? data?.ydImpStoreml?.allAccount : data?.ydImpStorefnbt?.total
						if (this.type == 1) {
							this.config = {
								'1': data.ydImpStoreml.saleamount,
								'2': data.ydImpStoreml.saleml,
								'3': -1 * data.ydImpStoreml.mlfc,
								'4': -1 * data.ydImpStoreml.ggfee,
								'5': -1 * data.ydImpStoreml.dftfee,
								'6': -1 * data.ydImpStoreml.czkfee,
								'7': -1 * data.ydImpStoreml.dkfee,
								"8": -1 * data.ydImpStoreml.sbfn,
								'9': -1 * data.ydImpStoreml.breadAccount,
								'10': -1 * data.ydImpStoreml.roomCharge,
								'11': -1 * data.ydImpStoreml.serviceCost,
								'12': -1 * data.ydImpStoreml.wzfee,
								'13': -1 * data.ydImpStoreml.others,
								'14': data.ydImpStoreml.storeml,
								'15': data.ydImpStoreml.cardAccount,
								'16': data.ydImpStoreml.ydygAccount,
								'17': data.ydImpStoreml.takeoutAccount,
								'18': data.ydImpStoreml.xyfn,
								'19': data.ydImpStoreml.clfee,
								'20': data.ydImpStoreml.douyinsaleml,
								'21': -1 * data.ydImpStoreml.sbfqcc,
								'22': -1 * data.ydImpStoreml.ttzxspkc,
								'23': data.ydImpStoreml.xypfdml,
								'24': -1 * data.ydImpStoreml.ppxyf,
								'25': -1 * data.ydImpStoreml.pdfy,
								'26': data.ydImpStoreml.yaoyc,
							}
							this.handlerPage(this.type, data.ydImpStoreml)
						} else if (this.type == 2) {
							this.config = {
								'1': data.ydImpStorefnbt.fmgdfbt,
								'2': data.ydImpStorefnbt.ksfnbt,
								'3': data.ydImpStorefnbt.hyjf,
								'4': data.ydImpStorefnbt.cxhdjl,
							}
							this.handlerPage(this.type, data.ydImpStorefnbt)
						}

						console.log(this.config)

					}
				} catch (e) {
					//TODO handle the exception
				}
			},
			// 处理数据
			handlerPage(val, data) {
				let obj = {
						'1': 'result',
						'2': 'resultType',
					},
					res = {
						result,
						resultType
					}
				// debugger
				let arr = res[obj[`${val}`]].dataPage
				// console.log(arr, "--")
				let arrAll = []
				for (let i = 0; i < arr.length; i++) {
					this.handlerKey(arr[i], i + 1, data, arrAll)
				}
				this.objectData = arrAll
				// console.log(this.objectData, "---dads")
			},
			//  key value 
			handlerKey(arr, i, data, newarr, _newarr) {
				newarr.push({
					name: arr,
					price: this.config[i] ? this.config[i] : 0
				})
				return newarr
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		$height: 48rpx;
		$color: rgb(51, 51, 51);
		$colorRed: rgb(255, 64, 64);

		%uniApp {
			display: flex;
			justify-content: center;
		}

		%textClass {
			font-size: 28rpx;
			font-weight: 400;
			line-height: 48rpx;
			letter-spacing: 0rpx;
			text-align: left;
		}

		%colorClass {
			color: $color;
			line-height: 48rpx;
			letter-spacing: 0rpx;
			text-align: center;
		}

		.uni-one,
		.uni-two {
			@extend %uniApp;
		}

		.class-main {
			margin-top: 32rpx;

			.uni-main {
				@extend %uniApp;
				justify-content: space-between;
				align-items: center;
				padding: 0 24rpx;

				.uni-left {
					height: 48rpx;
					color: rgb(102, 102, 102);
					@extend %textClass;
				}

				.uni-right {
					height: 48rpx;
					color: $color;
					@extend %textClass;
					text-align: right;
				}

				.colorRed {
					color: $colorRed;
				}
			}
		}



		.uni-one {
			height: $height;
			font-size: 24rpx;
			font-weight: 500;
			@extend %colorClass;
		}

		.uni-two {
			height: $height;
			font-size: 36rpx;
			font-weight: 400;
			@extend %colorClass;
		}

		width: 100%;
		min-height: calc(100vh );
		padding: 24rpx;
		// border: 2rpx solid;
		background-color: rgb(250, 250, 250);

	}
</style>